package com.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import com.server.entity.UpmsPermission;
import com.server.mapper.UpmsPermissionMapper;
import com.server.service.IUpmsPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import lombok.AllArgsConstructor;
import com.server.util.Result;
import java.util.ArrayList;

/**
 * <p>
 * 权限 服务实现类
 * </p>
 *
 * @author
 * @since 2020-04-03
 */
@Service
@AllArgsConstructor
public class UpmsPermissionServiceImpl extends ServiceImpl<UpmsPermissionMapper, UpmsPermission> implements IUpmsPermissionService {

	/**
	 * 新增
	 *
	 * @author
	 * @Date 2020-04-03
	 */
	@Override
	@Transactional(rollbackFor = {Exception.class})
	public Result add(UpmsPermission upmspermission){
		return this.baseMapper.insert(upmspermission)>0?Result.returnData(upmspermission):Result.error("操作失败");
	}

	/**
	 * 批量删除
	 *
	 * @author
	 * @Date 2020-04-03
	 */
	@Override
	@Transactional(rollbackFor = {Exception.class})
	public Boolean delete(String idsStr){
		String [] ids =idsStr.split(",");
		if(ids.length>0){
			List<String> resultList= new ArrayList<>(Arrays.asList(ids));
			if(this.baseMapper.deleteBatchIds(resultList)<=0){
				return false;
			}
		}
		return true;
	}

	/**
	 * 更新
	 *
	 * @author
	 * @Date 2020-04-03
	 */
	@Override
	@Transactional(rollbackFor = {Exception.class})
	public Result update(UpmsPermission upmspermission){
		return this.baseMapper.updateById(upmspermission)>0?Result.ok("操作成功"):Result.error("操作失败");
	}

	/**
	 * 根据id查询详情
	 *
	 * @author
	 * @Date 2020-04-03
	 */
	@Override
	public UpmsPermission findById(String id){
		return this.baseMapper.selectById(id);
	}


	/**
	 * 查询分页数据
	 *
	 * @author
	 * @Date 2020-04-03
	 */
	@Override
	public Result<List<UpmsPermission>> findPage(Page<UpmsPermission> page){
		return Result.createResult(this.baseMapper.selectPage(page,new QueryWrapper<UpmsPermission>().lambda().orderByDesc(UpmsPermission::getOrders)));
	}

}
